import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

/**
 * Input : file samsung4.txt
 * Format	: number of character in palindrome (it should be added by 1)
 * 			: The character
 * Output 	: print all the palindromes in horizontal / vertical side.
 */

/**
 * @author TrinhNX
 * @start_date	: 11-08-2015
 * @end_date 	:
 */
public class SamsungTest4 {
	private static final int NUM_TEST = 1;
	private static final int SIZE = 8;
	/**
	 * @author		: TrinhNX
	 * @param args
	 * @throws FileNotFoundException 
	 * @start_date	: 11-08-2015
	 * @end_date	:
	 */
	public static void main(String[] args) throws FileNotFoundException {
		SamsungTest4 test = new SamsungTest4();
		Scanner scanner = new Scanner(new File("data\\samsung4.txt"));
		for (int i = 0; i < NUM_TEST; i++) {
			final char[][] input = new char[SIZE][SIZE];
			// Read the input
			final int num_palind = scanner.nextInt() + 1;
			for (int index = 0; index < SIZE; index++) {
				input[index] = scanner.next().toCharArray();
			}

			// Horizontal
			for (int index = 0; index < SIZE; index++) {
				for (int padding = 0; padding < SIZE - num_palind + 1; padding++) {
					char c1 = input[index][padding];
					char c2 = input[index][padding + 1];
					char c3 = input[index][padding + 2];
					char c4 = input[index][padding + 3];
					char c5 = input[index][padding + 4];
					if (test.isPalindrome(num_palind, c1, c2, c3, c4, c5)) {
						StringBuilder sb = new StringBuilder(num_palind);
						sb.append(c1).append(c2).append(c3).append(c4).append(c5);
						System.out.println("Chuan cmnl: " + sb.toString());
					}
				}
			}

			// Vertical
			for (int padding = 0; padding < SIZE - num_palind + 1; padding++) {
				for (int ver = 0; ver < SIZE; ver++) {
					char c1 = input[padding][ver];
					char c2 = input[1 + padding][ver];
					char c3 = input[2 + padding][ver];
					char c4 = input[3 + padding][ver];
					char c5 = input[4 + padding][ver];
					if (test.isPalindrome(num_palind, c1, c2, c3, c4, c5)) {
						StringBuilder sb = new StringBuilder(num_palind);
						sb.append(c1).append(c2).append(c3).append(c4).append(c5);
						System.out.println("Chuan cmnl: " + sb.toString());
					}
				}
			}
		}
		scanner.close();
	}

	private boolean isPalindrome(final int size, char... cs) {
		if (cs.length != size)
			throw new IndexOutOfBoundsException("Not match size " + size);
		for (int i = 0; i < size / 2; i++) {
			if (cs[i] != cs[size - i - 1]) {
				return false;
			}
		}
		return true;
	}
}
